How to Sort by Selected Column

Sorry I have no Idea on how to do this. Thanks for the information.

DB Win
DBE List
string arr[] = { "GHI","DEF", "ABC"}
int i = sizeof(arr)
 
void test(DBE Elem, int j)
{
    int i = getSortColumn(List)
        setSortColumn(List, i)
        print i"\n"
}
 
 
 
 
Win = centered("Test")
List = listView(Win, listViewOptionSortText, 200, 10, arr, i)
 
realize(Win)
set(List, test)
insertColumn(List, 0, "Testing Sorting", 175, iconNone)
show(Win)

SystemAdmin - Tue Apr 06 12:21:22 EDT 2010

Re: How to Sort by Selected Column
llandale - Wed Apr 07 14:34:52 EDT 2010

Yes, the listView must have option listViewOptionSortText.

The sort callback must look like this:

//*******************
int    clbkfDbeLvSortFunction(string s1, s2)
{     // Standard sort function when defining a column as sortable.
        // Developers Note: Some code if added herein will cause DXL exception Violations.
        //      Don't understand why, but this function needs to be kept as-is.
        int     Result
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{} // all cases covered
        return(Result)
}  // end clbkfDbeLvSortFunction()


Change the name if you like, but changing the internals a little (like adding an empty line) messes it up, for reasons I cannot imagine.

You must set each sortable Column to be sortable, to use the above callback. In your case it looks like ColNum is zero.

 

set(List, ColNum, clbkfDbeLvSortFunction)

 

 

 

  • louie

 

 

Re: How to Sort by Selected Column
Mathias Mamsch - Thu Apr 08 04:33:19 EDT 2010

llandale - Wed Apr 07 14:34:52 EDT 2010

Yes, the listView must have option listViewOptionSortText.

The sort callback must look like this:

//*******************
int    clbkfDbeLvSortFunction(string s1, s2)
{     // Standard sort function when defining a column as sortable.
        // Developers Note: Some code if added herein will cause DXL exception Violations.
        //      Don't understand why, but this function needs to be kept as-is.
        int     Result
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{} // all cases covered
        return(Result)
}  // end clbkfDbeLvSortFunction()


Change the name if you like, but changing the internals a little (like adding an empty line) messes it up, for reasons I cannot imagine.

You must set each sortable Column to be sortable, to use the above callback. In your case it looks like ColNum is zero.

 

set(List, ColNum, clbkfDbeLvSortFunction)

 

 

 

  • louie

 

 

Louie, applying your code to his example and changing the sort function I do not get any exceptions on DOORS 8.2. Regards, Mathias
 

DB Win
DBE List
string arr[] = { "GHI","DEF", "ABC"}
int i = sizeof(arr)
 
int    clbkfDbeLvSortFunction(string s1, s2) {
        int     Result
        print "Crash me"
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        else              Result = -1
 
        return(Result)
}  // end clbkfDbeLvSortFunction()
 
Win = centered("Test")
List = listView(Win, listViewOptionSortText, 200, 10, arr, i)
realize(Win)
insertColumn(List, 0, "Testing Sorting", 175, iconNone)
set(List, 0, clbkfDbeLvSortFunction)
show(Win)

Re: How to Sort by Selected Column
SystemAdmin - Thu Apr 08 07:26:54 EDT 2010

llandale - Wed Apr 07 14:34:52 EDT 2010

Yes, the listView must have option listViewOptionSortText.

The sort callback must look like this:

//*******************
int    clbkfDbeLvSortFunction(string s1, s2)
{     // Standard sort function when defining a column as sortable.
        // Developers Note: Some code if added herein will cause DXL exception Violations.
        //      Don't understand why, but this function needs to be kept as-is.
        int     Result
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{} // all cases covered
        return(Result)
}  // end clbkfDbeLvSortFunction()


Change the name if you like, but changing the internals a little (like adding an empty line) messes it up, for reasons I cannot imagine.

You must set each sortable Column to be sortable, to use the above callback. In your case it looks like ColNum is zero.

 

set(List, ColNum, clbkfDbeLvSortFunction)

 

 

 

  • louie

 

 

I used this function and is amazing but I have the following issues:

1. Is sorting by ASCII Code which means that the upper "A" and lower "a" are not going to be in sequence (see example below)
2. Can the sort be both ascending and descending?
 

DB Win
DBE List
string arr[] = { "GHI","aEF", "ABC"}
int i = sizeof(arr)
 
int    clbkfDbeLvSortFunction(string s1, s2) {
        int     Result
        print "Crash me"
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        else              Result = -1
 
        return(Result)
}  // end clbkfDbeLvSortFunction()
 
Win = centered("Test")
List = listView(Win, listViewOptionSortText, 200, 10, arr, i)
realize(Win)
insertColumn(List, 0, "Testing Sorting", 175, iconNone)
set(List, 0, clbkfDbeLvSortFunction)
show(Win)

 


3. How can I use the function below?

 

 

 

setSortColumn 
Declaration 
void setSortColumn(DBE listView,
                    int columnIndex) 
Operation 
Sets the column to be sorted to the column specified by columnIndex. This works only for list views.

 

 

Re: How to Sort by Selected Column
Mathias Mamsch - Fri Apr 09 07:48:55 EDT 2010

SystemAdmin - Thu Apr 08 07:26:54 EDT 2010

I used this function and is amazing but I have the following issues:

1. Is sorting by ASCII Code which means that the upper "A" and lower "a" are not going to be in sequence (see example below)
2. Can the sort be both ascending and descending?
 

DB Win
DBE List
string arr[] = { "GHI","aEF", "ABC"}
int i = sizeof(arr)
 
int    clbkfDbeLvSortFunction(string s1, s2) {
        int     Result
        print "Crash me"
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        else              Result = -1
 
        return(Result)
}  // end clbkfDbeLvSortFunction()
 
Win = centered("Test")
List = listView(Win, listViewOptionSortText, 200, 10, arr, i)
realize(Win)
insertColumn(List, 0, "Testing Sorting", 175, iconNone)
set(List, 0, clbkfDbeLvSortFunction)
show(Win)

 


3. How can I use the function below?

 

 

 

setSortColumn 
Declaration 
void setSortColumn(DBE listView,
                    int columnIndex) 
Operation 
Sets the column to be sorted to the column specified by columnIndex. This works only for list views.

 

 

Hey Douglas,

ok, lets do a more complex example.

a) we take 2 columns instead of one
b) we implement a special sorting that will make the string "special" stick to the top
c) we make the sorting case independent
d) we switch the sorting when the user clicks a button
NOTE: The user can also click on the column headers to sort that column.
The answers to your questions very quickly:
1.+2. You can do any kind of sorting (see example). It depends on the sort function you employ. You can use different sort functions for every column and you need to set the sort function for each column using + set (dbeListview, iColumn, fnCallback)+.
3. You can control the sorting from code using this function (see button callbacks in the example)

Hope you get the idea, regards, Mathias

DB Win
DBE List
string arr[] = { "GHI","special","aEF", "ABC", "test", "Tool", "special","abc"}
int i = 4
 
int    clbkfDbeLvSortFunction(string s1, s2) {
        int     Result
        print "Comparing " s1 " and " s2 "\n"
 
        // these lines will make the string "special" stick to the top when sorted
        if (lower s1 == "special") return -1
        if (lower s2 == "special") return 1
 
        // otherwise do case independent sorting
        if     (lower s1 == lower s2) Result =  0
        elseif (lower s1 >  lower s2) Result =  1
        else              Result = -1
 
        return(Result)
}   
// sort the second column
void bt1Callback (DBE) { setSortColumn (List, 1) }
 
// sort the second column
void bt0Callback (DBE) { setSortColumn (List, 0) }
 
Win = centered("Test")
 
List = listView(Win, listViewOptionSortText, 200, 10, arr, i)
button(Win, "Sort 1st", bt0Callback)
beside Win
button(Win, "Sort 2nd", bt1Callback)
 
realize(Win)
// Two columns now
insertColumn(List, 0, "Testing Sorting", 85, iconNone)
insertColumn(List, 1, "2nd Column", 85, iconNone)
 
for i in 4:7 do set(List, i-4, 1,arr[i] )
 
set(List, 0, clbkfDbeLvSortFunction)
set(List, 1, clbkfDbeLvSortFunction)
 
// we start unsorted ...
show(Win)

Re: How to Sort by Selected Column
llandale - Fri Apr 09 13:28:06 EDT 2010

SystemAdmin - Thu Apr 08 07:26:54 EDT 2010

I used this function and is amazing but I have the following issues:

1. Is sorting by ASCII Code which means that the upper "A" and lower "a" are not going to be in sequence (see example below)
2. Can the sort be both ascending and descending?
 

DB Win
DBE List
string arr[] = { "GHI","aEF", "ABC"}
int i = sizeof(arr)
 
int    clbkfDbeLvSortFunction(string s1, s2) {
        int     Result
        print "Crash me"
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        else              Result = -1
 
        return(Result)
}  // end clbkfDbeLvSortFunction()
 
Win = centered("Test")
List = listView(Win, listViewOptionSortText, 200, 10, arr, i)
realize(Win)
insertColumn(List, 0, "Testing Sorting", 175, iconNone)
set(List, 0, clbkfDbeLvSortFunction)
show(Win)

 


3. How can I use the function below?

 

 

 

setSortColumn 
Declaration 
void setSortColumn(DBE listView,
                    int columnIndex) 
Operation 
Sets the column to be sorted to the column specified by columnIndex. This works only for list views.

 

 

I struggled through this a couple years ago; I don't actually remember much but I wrote a suite of ListView functions and am looking at these and also looking at a program that does this successfully.

The sort function itself was very touchy, sometimes when I added something benign to it, it would not work. I don't recall the exact details, but it seems to me that adding a line caused very strange behavior. Not all changes caused exceptions; perhaps it was just inside the if-elseif- statements. Looking inside the doors.exe I see that this function can actually have any type of parameters, not just strings, and I'm suspecting that is the cause of errors.

((Mindlessly digressing: this seems similar to Skip Lists that must be defined with createString() to handle string Keys that may be originally constants OR variables...the 'key' in Skips can be of any type also... Perhaps my testing was with constant arrays, rather than arrays populated with variable values...))

I don't recall the details of the sorting, you can experiment and figure that out. A < a; A < z?

I imagine if you tweak the sort function changing the > sign to <, it should do a reverse sort. If you want a clever toggle sort (like all other GUI columns), you'd have to change the sort function to cleverly remember ListView DBE and Column and how its currently sorted (if at all), and figure out to do a > or < return. However, like I said, the function is tempermental and I doubt you will succeed.

The setSortColumn() function will perform a sort on the column, so long as its set up originally for sorting.

  • Louie